﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Web;
using System.Web.Http;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using CloudApiServer.Services;
using Google.Protobuf.WellKnownTypes;
using log4net;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.X500;
using Org.BouncyCastle.Asn1.X509;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
using static log4net.Appender.RollingFileAppender;

namespace CloudApiServer.Controllers
{
    /// <summary>
    /// 湖南医保接口控制器
    /// </summary>
    [RoutePrefix("isp-api")]
    public class FsiApiHuNanController : ApiController
    {
        private readonly SignInSignOutService _signInSignOuService;
        private readonly FsiPsnInfoService _fsiPsnInfoService;
        private readonly FsiDrugStoreService _fsiDrugStoreService;
        private readonly CatalogQueryService _catalogQueryService;
        private readonly FsiIntegratedQueryService _fsiIntegratedQueryService;
        private readonly YbSettlementStmtService _ybSettlementStmtService;
        private readonly RiskConService _riskConService;
        private readonly FileuploadService _fileuploadService;
        private readonly GoodsService _goodsService;
        private readonly OutpatientDocInfoService _outpatientDocInfoService;
        private readonly FsiReverseService _fsiReverseService;
        public FsiApiHuNanController()
        {
            _signInSignOuService = new SignInSignOutService();
            _fsiPsnInfoService = new FsiPsnInfoService();
            _fsiDrugStoreService = new FsiDrugStoreService();
            _catalogQueryService = new CatalogQueryService();
            _fsiIntegratedQueryService = new FsiIntegratedQueryService();
            _ybSettlementStmtService = new YbSettlementStmtService();
            _riskConService = new RiskConService();
            _fileuploadService = new FileuploadService();
            _goodsService = new GoodsService();
            _outpatientDocInfoService = new OutpatientDocInfoService();
            _fsiReverseService = new FsiReverseService();
        }
        /*接口*/
        /// <summary>
        /// 医保接口没找到的统一接口返回
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [HttpPost]
        public IHttpActionResult FsiNotFound(HttpRequestMessage request)
        {
            string url = request.RequestUri.ToString();
            string Method = request.Method.ToString();
            string Errnum = LogHelper.GetErrornumber();
            try
            {
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参为空！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
                else
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                    string infno = fsiRequest.infno;
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加！当前请求的接口号：{infno},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
            }
            catch (JsonReaderException)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参格式不正确！服务端无法正常反序列化！请检查入参是否为Json格式！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);

            }
            catch (Exception ex)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且服务端程序处理异常！请联系管理员排查！当前异常提示：{ex.Message},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);
            }
        }
        /// <summary>
        /// 湖南医保总接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("powercsb")]
        public async Task<IHttpActionResult> powercsb(HttpRequestMessage request)
        {
            try
            {
                if (FsiDatainfo.stateFsiApi == false)
                {
                    throw new Exception("该接口已被控制台停用！请联系管理员！");
                }
                var fsiRequestabc = JsonConvert.DeserializeObject<FsiRequestHeader<object>>(request.Content.ReadAsStringAsync().Result);
                string infno = fsiRequestabc.infno;
                if (string.IsNullOrEmpty(infno))
                {
                    throw new Exception($"传入的参数有误!未获取到接口号infno,请检查入参！当前入参：{request.Content.ReadAsStringAsync().Result}");
                }
                if (FsiDatainfo.statesignon == true  && infno != "9001" && infno != "9002")
                {
                    bool sign = await _signInSignOuService.SignInStateAsync(fsiRequestabc.fixmedins_code, fsiRequestabc.opter, fsiRequestabc.sign_no);
                    if (sign == false)
                    {
                        throw new Exception("校验签到信息失败：未查询到有效的签到信息！");
                    }
                }
                string fsiadmvs = fsiRequestabc.mdtrtarea_admvs.Substring(0, 2);
                switch (infno)
                {
                    case "9001":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(await request.Content.ReadAsStringAsync());
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var signin = await _signInSignOuService.SignInAsync(fsiRequest, this.GetType().Name);
                            var response = new FsiHeader<outputsignInOut>
                            {
                                output = signin,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(response);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "9002":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignOut>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var siginout = await _signInSignOuService.SignOutAsync(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                output = siginout,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "1101":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputQueryPsnInfoRequest>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var queryPsnInfo = await _fsiPsnInfoService.QueryPsnInfo(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputQueryPsnInfo>
                            {
                                output = queryPsnInfo,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "2101":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputDrugstoreSettleAccountsPreA>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var drugstoreSettleAccountsPreA = await _fsiDrugStoreService.DrugstoreSettleAccountsPre(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputDrugstoreSettleAccountsPreA>
                            {
                                output = drugstoreSettleAccountsPreA,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "2102":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputDrugstoreSettleAccountsPreA>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var drugstoreSettleAccountsA = await _fsiDrugStoreService.DrugstoreSettleAccounts(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputDrugstoreSettleAccountsPreA>
                            {
                                output = drugstoreSettleAccountsA,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "2103":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputDrugstoreSettleRevokeRequest>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var drugstoreSettleRevoke = await _fsiDrugStoreService.DrugstoreSettleRevoke(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputDrugstoreSettleRevoke>
                            {
                                output = drugstoreSettleRevoke,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "2601":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputRevsMethod>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            bool flag = await _fsiReverseService.RevsMethod(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    output = null,
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用冲正服务FsiReverseService.RevsMethod返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3301":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputCatalogCompUp>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            bool flag = await _catalogQueryService.CatalogCompUp(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    output = null,
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用目录上传服务CatalogQueryService.CatalogCompUp返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3302":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputDeleteCatalogCompAudited>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            bool flag = await _catalogQueryService.DeleteCatalogCompAudited(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    output = null,
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用目录上传服务CatalogQueryService.DeleteCatalogCompAudited返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "1317":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputQueryMedListMapByPageRequest>>(request.Content.ReadAsStringAsync().Result);
                            DateTime dateTime = DateTime.Now;
                            Random rnd = new Random();
                            var outputQueryMedListMapByPage = await _catalogQueryService.QueryMedListMapByPage(fsiRequest, this.GetType().Name);
                            FsiHeader<OutputQueryMedListMapByPage> FsiHeader = new FsiHeader<OutputQueryMedListMapByPage>
                            {
                                output = outputQueryMedListMapByPage,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3201":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputStmtTotalRequest>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var stmtinfo = await _ybSettlementStmtService.StmtTotal(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputStmtTotal>
                            {
                                output = stmtinfo,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3202":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputStmtDetailRequest>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var fileinfo = await _ybSettlementStmtService.StmtDetail(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputStmtDetail>
                            {
                                output = fileinfo,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "5301":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputQueryPsnOpspReg>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var outputQueryPsnOpspReg = await _fsiIntegratedQueryService.QueryPsnOpspReg(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputQueryPsnOpspReg>
                            {
                                output = outputQueryPsnOpspReg,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "5206":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputQueryFixmedinsPracPsnSum>>(request.Content.ReadAsStringAsync().Result);
                            string psn_no = fsiRequest.Input.data.psn_no;
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var outputCuminfo = await _fsiIntegratedQueryService.QueryFixmedinsPracPsnSum(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<outputCuminfo>
                            {
                                output = outputCuminfo,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3101":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputRiskConServiceresult>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var outputriskConService = await _riskConService.BeforeAnalyze(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputriskConService>
                            {
                                output = outputriskConService,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3102":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputRiskConServiceresult>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var outputriskConService = await _riskConService.CourseAnalyze(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputriskConService>
                            {
                                output = outputriskConService,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3501":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpload>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsUpload(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsUpload返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3502":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpdate>>(request.Content.ReadAsStringAsync().Result);
                            DateTime dateTime = DateTime.Now;
                            Random rnd = new Random();
                            var flag = await _goodsService.GoodsUpdate(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsUpdate返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3503":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsBuy(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsBuy返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3504":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsBuyReturn(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsBuyReturn返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3505":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSell>>(request.Content.ReadAsStringAsync().Result);
                            if (FsiDatainfo.stateFsiApi == false)
                            {
                                throw new Exception("该接口已被控制台停用！请联系管理员！");
                            }
                            if (FsiDatainfo.statesignon == true)
                            {
                                bool sign = await _signInSignOuService.SignInStateAsync(fsiRequest.fixmedins_code, fsiRequest.opter, fsiRequest.sign_no);
                                if (sign == false)
                                {
                                    throw new Exception("校验签到信息失败：未查询到有效的签到信息！");
                                }
                            }
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsSell(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsSell返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3506":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSell>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsSellReturn(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsSellReturn返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3507":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsInfoDelete>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsInfoDelete(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsInfoDelete返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "9101":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputFileupload>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var outputFileUpload = await _fileuploadService.Upload(fsiRequest, this.GetType().Name);
                            var FsiHeader = new FsiHeader<OutputFileUpload>
                            {
                                output = outputFileUpload,
                                infcode = 0,
                                warn_msg = null,
                                cainfo = null,
                                err_msg = "success",
                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                signtype = null,
                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                            };
                            return Json(FsiHeader);

                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "9102":
                        try
                        {
                            var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputFileDownload>>(request.Content.ReadAsStringAsync().Result);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var output = await _fileuploadService.Download(fsiRequest, this.GetType().Name);
                            return ResponseMessage(output);
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    default:
                        throw new Exception($"[湖南医保自定义接口]接口号{infno}未被定义，请检查入参或联系管理员！");
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用湖南医保自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                };
                return Json(FsiHeader);
            }
        }
    }
}
